package com.archie.xunji.guanzhu.entitys;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by xqx on 2015/11/10.
 */
public class People {
    private String nickname;
    private String username;
    private String headurl;
    private int userinfoid;

    public static List<People> getDataList(String json){
        List<People> list = null;
        if (json != null) {
            try {
                list = new ArrayList<>();
                JSONObject obj = null;
                obj = new JSONObject(json);
                JSONObject result = obj.getJSONObject("result");
                JSONArray data = result.getJSONArray("data");
                People people = null;
                for (int i = 0; i < data.length(); i++) {
                    JSONObject p = data.getJSONObject(i);
                    String un = p.getString("username");
                    String nn = p.getString("nickname");
                    int id = p.getInt("userinfoid");
                    String url = p.getString("headurl");
                    people = new People();
                    people.setHeadurl("http://imagecdn.xunjimap.com/image/"+url);
                    people.setNickname(nn);
                    people.setUsername(un);
                    people.setUserinfoid(id);
                    list.add(people);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return list;
    }

    @Override
    public String toString() {
        return "People{" +
                "nickname='" + nickname + '\'' +
                ", username='" + username + '\'' +
                ", headurl='" + headurl + '\'' +
                ", userinfoid=" + userinfoid +
                '}';
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public void setHeadurl(String headurl) {
        this.headurl = headurl;
    }

    public void setUserinfoid(int userinfoid) {
        this.userinfoid = userinfoid;
    }

    public String getNickname() {
        return nickname;
    }

    public String getUsername() {
        return username;
    }

    public String getHeadurl() {
        return headurl;
    }

    public int getUserinfoid() {
        return userinfoid;
    }
}
